package com.koicarp.agent.workflow.deepseek;

import com.koicarp.agent.workflow.OllamaChatModelBuild;
import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.data.message.ChatMessage;
import dev.langchain4j.data.message.SystemMessage;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.output.Response;
import dev.langchain4j.service.AiServices;

import java.util.*;

/**
 * @Author: liuxia
 * @CreateTime: 2025/2/24 上午10:54
 * @Description:
 */
public class SaTest {

    public static void main(String[] args) throws NoSuchFieldException {
        String userMessageText = "今日检查了花王企业，我要一份检查单";
        String systemMessageText = "你是上海守安投资控股集团业务分类小助手，能通过用户的输入，精确分类";
        ChatLanguageModel model = OllamaChatModelBuild.build(OllamaChatModelBuild.DEEP_7B);

        // 处理枚举
        DeepEnumOutputParser outputParser = new DeepEnumOutputParser(SaChatTypeEnum.class);
        String typeEnumMessage = outputParser.formatInstructions();

        // 设置prompt
        List<ChatMessage> messages = new ArrayList<>();
        UserMessage userMessage = UserMessage.from(userMessageText + typeEnumMessage);
        messages.add(userMessage);
        SystemMessage systemMessage = SystemMessage.from(systemMessageText);
        messages.add(systemMessage);

        Response<AiMessage> generate = model.generate(messages);
        String text = generate.content().text();
        SaChatTypeEnum typeEnum = (SaChatTypeEnum) outputParser.parse(SaChatTypeEnum.class, text);

        switch (typeEnum) {
            case CHECK_LIST:
                CheckListAssistant checkListAssistant = AiServices.builder(CheckListAssistant.class)
                        .chatLanguageModel(model)
                        .chatMemoryProvider(memoryId -> MessageWindowChatMemory.withMaxMessages(10))  // 保存10个上下文用户语句
//                        .tools(new DateTool()) // 加了tool如果不存在日期，会使用当前日期 // G了，deepseek-r1不支持tools
                        .build();
                Check check = checkListAssistant.generateCheckList(1, "生成花王化工有限公司的甲类罐区-0115-1459检查单，日期是2025年1月21号，由刘涛，陈萱，黄俊辉检查");
//  测试tool              Check check = checkListAssistant.generateCheckList(1, "生成花王化工有限公司的甲类罐区-0115-1459检查单，刘涛，陈萱，黄俊辉检查");
                System.out.println(check);


            case VIOLATE_TERMS:
        }
    }

}
